﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using V5_BLL;
using V5_Common;
using V5_Model;

namespace V5_EShop.Admin {
    public partial class Admin_ProductComment : BasicPage {
        protected void Page_Load(object sender, EventArgs e) {
            if (!this.IsPostBack) {
                Bind_gvList();
            }
        }

        private void Bind_gvList() {
            this.MultiViewList.ActiveViewIndex = 0;
            int count = 0;
            this.gvList.DataSource = new BLLProductComment().GetList(Pager.PageSize, Pager.CurrentPageIndex, "", ref count).Tables[0];
            this.Pager.RecordCount = count;
            this.gvList.DataBind();
        }

        protected void Pager_PageChanged(object sender, EventArgs e) {
            Bind_gvList();
        }

        private void Bind_DataReply(int id) {
            this.MultiViewList.ActiveViewIndex = 1;
            ModelProductComment model = new BLLProductComment().GetModel(id);
            if (model != null) {

                var productModel = new BLLProduct().GetModel(model.ProductID);

                lbl1.Text = productModel.ProductName;
                lbl2.Text = model.CommentName;
                lbl3.Text = model.CommentEmail;
                string str1 = "综合评价:", str2 = "外观评价:", str3 = "舒适评价:", str4 = "尺码评价:";
                switch (model.Pmost) {
                    case 1:
                        str1 += "好评";
                        break;
                    case 2:
                        str1 += "中评";
                        break;
                    case 3:
                        str1 += "差评";
                        break;
                }

                switch (model.Pmost1) {
                    case 1:
                        str2 += "好评";
                        break;
                    case 2:
                        str2 += "中评";
                        break;
                    case 3:
                        str2 += "差评";
                        break;
                }

                switch (model.Pmost2) {
                    case 1:
                        str3 += "好评";
                        break;
                    case 2:
                        str3 += "中评";
                        break;
                    case 3:
                        str3 += "差评";
                        break;
                }

                switch (model.Pmost3) {
                    case 1:
                        str4 += "合适";
                        break;
                    case 2:
                        str4 += "偏大";
                        break;
                    case 3:
                        str4 += "偏小";
                        break;
                }
                lbl4.Text = str1 + "--" + str2 + "--" + str3 + "--" + str4;
                lbl5.Text = model.CommentContent;
                hfID.Value = model.ID.ToString();

            }
        }
        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e) {
            string eName = InputHelper.SetString(e.CommandName);
            int id = InputHelper.SetInt(e.CommandArgument);
            switch (eName.ToLower().Trim()) {
                case "reply":
                    Bind_DataReply(id);
                    break;
                case "del":

                    break;
                default:
                    break;
            }
        }

        private void Bind_Delete(int id) {
            new BLLProductComment().Delete(id);
            this.Bind_gvList();
        }


        protected void btnSave_Click(object sender, EventArgs e) {
            int id = InputHelper.SetInt(hfID.Value);
            string ReplyComment = txtReplyComment.Text;
            int passed = this.chkPassed.Checked ? 1 : 0;
            ModelProductComment model = new ModelProductComment();
            BLLProductComment bll = new BLLProductComment();
            model.ID = id;
            model.ReplyComment = ReplyComment;
            model.Passed = passed;
            if (id == 0) {

            }
            else if (id > 0) {
                bll.Update_Reply(model);
            }
            this.Bind_gvList();
        }
    }
}
